﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

/**Class: DateTime StartOfWeek
    * @author Victor Moy
    * @version 1.0
    * Course : ITEC 4860 Spring 2012
    * Written: March 29, 2012
    *
    *This class returns the date of the next Sunday according to a date that is entered
    *
    * Purpose: Return the next sunday from a certain date as a basis for scheduling
    */

namespace Scheduler.Business_Logic_Layer
{
    public static class DateTimeExtensions
    {
        public static DateTime StartOfWeek(this DateTime dt, DayOfWeek startOfWeek)
        {
            int diff = dt.DayOfWeek - startOfWeek;
            if (diff < 0)
            {
                diff += 7;
            }

            return dt.AddDays(-1*diff).Date;
        }
    }

}
